﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using estudent.Models;

namespace estudent.Controllers
{
    public class IskanjeStudentController : Controller
    {
        //
        // GET: /IskanjeStudent/

        public ActionResult Index()
        {
            return View("IskanjeStudent");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public string Poisci(FormCollection form)
        {
            estudentEnt entitete = new estudentEnt();
            string vpisna=form["vpisna"];
            string ime=form["ime"];
            string pri=form["priimek"];

            IEnumerable<Studenti> iskaniStudenti = from s in entitete.Studentis
                                                   where s.username.StartsWith(vpisna) && s.ime.StartsWith(ime) && s.priimek.StartsWith(pri)
                                                   orderby s.priimek, s.ime
                                                   select s;

            string ret="";
            ret += "<tr align='center'><th>Št.</th><th>Ime</th><th>Priimek</th><th>Vpisna</th><th>&nbsp;</th></tr>";
            int i = 1;
            foreach (var student in iskaniStudenti)
            {

                ret += ("<tr align='center'>");
                ret += "<td  style='width:45px;'>" + i + ".</td>";
                ret += ("<td style='width:125px;'>" + student.ime + "</td><td  style='width:125px;'>" + student.priimek + "</td><td style='width:125px;'>" + student.username + "</td>");

                if (form["namen"].CompareTo("urejanjeVpisnegaLista") == 0)
                    ret += ("<td  style='width:125px;'><a href='Uredi/" + student.username + "'>izberi</a></td>");
                else if (form["namen"].CompareTo("dodajanjeVpisnegaLista") == 0)
                {
                    ret += ("<td  style='width:125px;'><a href='Dodaj/" + student.username + "'>izberi</a></td>");
                }
                else if (form["namen"].CompareTo("vpisovanjeSPrijavnice") == 0)
                {
                    ret += ("<td  style='width:125px;'><a href='VnosPrijavnica/Predmeti/" + student.username + "'>izberi</a></td>");
                }
                else if (form["namen"].CompareTo("odjavaIzpitaReferentka") == 0)
                {
                    ret += ("<td  style='width:125px;'><a href='OdjavaIzpitaReferentka/Roki/" + student.username + "'>izberi</a></td>");
                }
                else if (form["namen"].CompareTo("KartotecniListRefer") == 0)
                {
                    ret += ("<td  style='width:125px;'><a href='KartotecniListRefer/Seznam/" + student.username + "'>izberi</a></td>");
                }
                else if (form["namen"].CompareTo("osebniPodatki") == 0)
                {
                    ret += ("<td  style='width:125px;'><a href='OsebniPodatki/Podatki/" + student.username + "'>izberi</a></td>");
                }
                else if (form["namen"].CompareTo("PrijavaIzpitRef") == 0)
                {
                    ret += ("<td  style='width:125px;'><a href='PrijavaIzpitRef/Prijavi/" + student.username + "'>izberi</a></td>");
                }

                ret += ("</tr>");
                i++;
            }
            return ret;
        }

    }
}
